feat(chat-headers): propagate the resolved user ID via tracestate - #2
Merged
Conversation
Providers that receive W3C trace context now also receive the resolved `user.id` as an extra tracestate member, merged into the tracestate produced by propagation. The injection sits behind the existing OPENCODE_TRACE_PROPAGATION_PROVIDERS gate, so a tracestate is never sent without its traceparent. Two new settings control it: OPENCODE_USER_ID_TRACESTATE_ENABLED (default true) and OPENCODE_USER_ID_TRACESTATE_KEY (default opencode_user_id). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Providers that receive W3C trace context now also receive the resolved
user.idas an extratracestatemember:The member is merged into the
tracestateproduced by propagation rather than replacing it.Why gated on trace propagation
The injection sits behind the existing
OPENCODE_TRACE_PROPAGATION_PROVIDERScheck, right afterinjectTraceContext. Per W3C, atracestatewithout a matchingtraceparentshould be dropped by compliant receivers, so tying the two together avoids emitting a header that a standard OTel propagator would silently ignore. Enabling propagation for a provider enables the user ID for it too — no separate opt-in.Configuration
userIDTracestateEnabledOPENCODE_USER_ID_TRACESTATE_ENABLEDtrueuserIDTracestateKeyOPENCODE_USER_ID_TRACESTATE_KEYopencode_user_idThe default key uses underscores to stay within the W3C
tracestatekey syntax (lowercase letters, digits,_,-,*,/— no dots).Skipped cases
Nothing is injected when the user ID is still unresolved (
unknown), when the value contains characters invalid in atracestatevalue (,,=, non-printable ASCII), or when the feature is disabled.Notes
UNKNOWN_USER_IDis now exported fromsrc/user-id.tsso the handler shares the constant instead of duplicating the literal.bun run typecheckpasses;bun testis 229/229 green (8 new cases acrosstests/chat-headers.test.tsandtests/config.test.ts).oxfmt/oxlintare not installed in this checkout, soformat:checkandlintwere not run.🤖 Generated with Claude Code